package cn.sylinx.horm.dialect.sql;

import cn.sylinx.horm.util.Tuple;

class SqliteSqlBuilder extends DefaultSqlBuilder {

    @Override
    public Tuple buildPaginatorSql(String preSql, int pageNumber, int pageSize) {

        String sqlCount = "SELECT COUNT(1) AS totalCount FROM (" + preSql + ") AS temp";
        String sql = preSql + " LIMIT ?, ? ";
        int beginIndex = pageSize * (pageNumber - 1) + 1;
        int endIndex = pageSize * pageNumber;
        Object[] params = new Object[] { beginIndex, endIndex };
        return Tuple.apply(sqlCount, sql, params);
    }

    @Override
    public String buildValidateQuery() {
        return "select 1";
    }

}
